from flask import g
import time
import pigpio


class Led:
    def __init__(self, channel):
        self.channel = channel
        self.pi = g.pi
        self.pi.set_mode(self.channel, pigpio.OUTPUT)
        self.pi.write(self.channel, pigpio.LOW)

    def flicker(self, times=1, duration=0.15, interval=0.15):
        for item in range(times):
            self.on()
            time.sleep(duration)
            self.off()
            if times > 1:
                time.sleep(interval)

    def on(self):
        self.pi.write(self.channel, pigpio.HIGH)

    def off(self):
        self.pi.write(self.channel, pigpio.LOW)

